home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / dirutil.c < prev    next >
C/C++ Source or Header  |  1992-05-14  |  1KB  |  79 lines

  1. /* @(#) $Header: dirutil.c,v 1.9 92/05/14 13:19:53 deyke Exp $ */
  2.  
  3. #include <sys/types.h>
  4.  
  5. #include <errno.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <sys/rtprio.h>
  9. #include <sys/stat.h>
  10. #include <unistd.h>
  11. #include "global.h"
  12. #include "dirutil.h"
  13. #include "commands.h"
  14.  
  15. extern char *sys_errlist[];
  16.  
  17. /* Create a directory listing in a temp file and return the resulting file
  18.  * descriptor. If full == 1, give a full listing; else return just a list
  19.  * of names.
  20.  */
  21. FILE *
  22. dir(path,full)
  23. char *path;
  24. int full;
  25. {
  26.     int fd[2];
  27.  
  28.     if(pipe(fd))
  29.         return NULLFILE;
  30.     switch(fork()) {
  31.     case -1:
  32.         close(fd[0]);
  33.         close(fd[1]);
  34.         return NULLFILE;
  35.     case 0:
  36.         rtprio(0,RTPRIO_RTOFF);
  37.         close(fd[0]);
  38.         dup2(fd[1],1);
  39.         dup2(fd[1],2);
  40.         close(fd[1]);
  41.         execl("/bin/ls",
  42.               "ls",
  43. #if defined(ISC) || defined(SCO)
  44.               full ? "-l" : "-x",
  45. #else
  46.               full ? "-Al" : "-A",
  47. #endif
  48.               path,
  49.               (char *) 0);
  50.         exit(1);
  51.     default:
  52.         close(fd[1]);
  53.         return fdopen(fd[0],"r");
  54.     }
  55. }
  56.  
  57. /* Create directory */
  58. int
  59. domkd(argc,argv,p)
  60. int argc;
  61. char *argv[];
  62. void *p;
  63. {
  64.     if(mkdir(argv[1],0777) == -1)
  65.         printf("Can't make %s: %s\n",argv[1],sys_errlist[errno]);
  66.     return 0;
  67. }
  68. /* Remove directory */
  69. int
  70. dormd(argc,argv,p)
  71. int argc;
  72. char *argv[];
  73. void *p;
  74. {
  75.     if(rmdir(argv[1]) == -1)
  76.         printf("Can't remove %s: %s\n",argv[1],sys_errlist[errno]);
  77.     return 0;
  78. }
  79.